﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入需要录入学生成绩的人数:");
            int a = int.Parse(Console.ReadLine());
            int sum = 0;
            for (int i = 0; i < a; i++)
            {
                int score = 0;
                if (score >= 0 && score <= 100)
                {
                    try
                    {
                        Console.WriteLine("请输入第" + (i + 1) + "学生的成绩");
                        score = int.Parse(Console.ReadLine());
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("异常已处理");
                        Console.WriteLine(e.Source);
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine(e.Message);
                        Console.WriteLine("请重新输入第" + (i + 1) + "学生的成绩");
                        score = int.Parse(Console.ReadLine());
                    }
                    catch (OverflowException e)
                    {
                        Console.WriteLine("异常已处理");
                        Console.WriteLine(e.Source);
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine(e.Message);
                        Console.WriteLine("请重新输入第" + (i + 1) + "学生的成绩");
                        score = int.Parse(Console.ReadLine());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("异常已处理");
                        Console.WriteLine(e.Source);
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine(e.Message);
                        Console.WriteLine("请重新输入第" + (i + 1) + "学生的成绩");
                        score = int.Parse(Console.ReadLine());
                    }
                    finally
                    {
                        Console.WriteLine("第" + (i + 1) + "个学生成绩输入完成");
                    }
                    sum += score;
                }
            }
            Console.WriteLine("总学生数为:" + a);
            Console.WriteLine("学生总分数为:" + sum);
            Console.WriteLine("学生平均分为:" + sum / a);
            Console.ReadKey();
        }
    }
}

